Update JSON parser test and docs
authorMattias Engdegård <mattiase@acm.org>
Mon, 1 Apr 2024 14:58:03 +0000 (16:58 +0200)
committerMattias Engdegård <mattiase@acm.org>
Mon, 1 Apr 2024 15:07:04 +0000 (17:07 +0200)
* test/src/json-tests.el (json-parse-string/object):
Duplicated object keys are now retained in alist and plist output.
* etc/NEWS: Mention it.

etc/NEWS
test/src/json-tests.el

index e575fc2936e254f70b465451ba169480000109cc..4b0f148dc5d0d25740408740639e7b3195976b7b 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1721,8 +1721,16 @@ Use a float value for the first argument instead.
 Instead, use 'eshell-process-wait-time', which supports floating-point
 values.
 
+** JSON
+
+---
+*** The parser keeps duplicated object keys in alist and plist output.
+A JSON object such as '{"a":1,"a":2}' will now be translated into the
+Lisp values '((a . 1) (a . 2))' or '(:a 1 :a 2)' if alist or plist
+object types are requested.
+
 ---
-** The JSON parser sometimes signals different types of errors.
+*** The parser sometimes signals different types of errors.
 It will now signal 'json-utf8-decode-error' for inputs that are not
 correctly UTF-8 encoded.
 
index 628a5a3de575dbcec40fc5a9415cfeebc001ff5e..8b730ef8c909363acc1d6fe170d17ba9b123edee 100644 (file)
   )
 
 (ert-deftest json-parse-string/object ()
-  :expected-result :failed
-  ;; FIXME: This currently fails. Should the parser deduplicate keys?
-  ;; Never, always, or for alist and plist only?
   (let ((input
          "{ \"abc\" : [1, 2, true], \"def\" : null, \"abc\" : [9, false] }\n"))
     (let ((actual (json-parse-string input)))
       (should (equal (cl-sort (map-pairs actual) #'string< :key #'car)
                      '(("abc" . [9 :false]) ("def" . :null)))))
     (should (equal (json-parse-string input :object-type 'alist)
-                   '((abc . [9 :false]) (def . :null))))
+                   '((abc . [1 2 t]) (def . :null) (abc . [9 :false]))))
     (should (equal (json-parse-string input :object-type 'plist)
-                   '(:abc [9 :false] :def :null)))))
+                   '(:abc [1 2 t]  :def :null :abc [9 :false])))))
 
 (ert-deftest json-parse-string/object-unicode-keys ()
   (let ((input "{\"é\":1,\"☃\":2,\"𐌐\":3}"))